﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Kontakt", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(Kontakt))]
    public class KontaktSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKontakt clazz;
        
        public KontaktSerializer(IKontakt clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Aadress!=null) {
                Writer.WriteStartElement("Aadress");
                global::Xtee.Core.SerializationMetadata metaAadress = this.GetMetaData(clazz.Aadress);
                Writer.WriteTypeAttribute(metaAadress.TypeQualifiedName.Namespace, metaAadress.TypeQualifiedName.Name);
                metaAadress.NewSerializer(clazz.Aadress).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.KontaktTekst!=null) {
                Writer.WriteStartElement("KontaktTekst");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KontaktTekst))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LiikKL!=null) {
                Writer.WriteStartElement("LiikKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.LiikKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.StaatusKL!=null) {
                Writer.WriteStartElement("StaatusKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.StaatusKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AlgusKP!=null) {
                Writer.WriteStartElement("AlgusKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.AlgusKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LoppKP!=null) {
                Writer.WriteStartElement("LoppKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.LoppKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SulgemiseKP!=null) {
                Writer.WriteStartElement("SulgemiseKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.SulgemiseKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Markused!=null) {
                Writer.WriteStartElement("Markused");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Markused))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Aadress") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaAadress = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IAadress>(Reader, "Aadress", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                    clazz.Aadress = metaAadress.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IAadress>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Aadress");
                        metaAadress.NewSerializer(clazz.Aadress).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="KontaktTekst") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.KontaktTekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("KontaktTekst")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="LiikKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.LiikKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("LiikKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="StaatusKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.StaatusKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("StaatusKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AlgusKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AlgusKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("AlgusKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="LoppKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.LoppKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("LoppKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="SulgemiseKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SulgemiseKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("SulgemiseKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Markused") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Markused = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Markused")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
